package com.iflytek.aiuiproduct.handler.disposer;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;

import com.iflytek.aiuiproduct.handler.entity.SemanticResult;
import com.iflytek.aiuiproduct.handler.entity.ServiceType;

public class TranslationDisposer extends Disposer {

	private  final String KEY_DATA= "data";
	private  final String KEY_RESULT = "result";
	private  final String KEY_TRANSLATED = "translated";
	
	public TranslationDisposer(Context context) {
		super(context);
	}

	@Override
	public void disposeResult(SemanticResult result) {
		
		try {
			JSONObject resultObj = result.getData();
			JSONArray resultArray = resultObj.getJSONArray(KEY_RESULT);
			String translated = resultArray.getJSONObject(0).getString(KEY_TRANSLATED);
			getPlayController().justTTS("", translated);
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	@Override
	public boolean canHandle(ServiceType type) {
		if (type.equals(ServiceType.TRANSLATION)) {
			return true;
		}
		return false;
	}

}
